home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1999 Spring / macformat-077.iso / Shareware Plus / Development / Akua Sweets 131 / Akua Sweets Examples / System / PowerBook PRAM Check < prev    next >
Encoding:
Text File  |  1999-03-04  |  3.4 KB  |  107 lines  |  [TEXT/ToyS]

  1. -- Needs Akua Sweets V1.29 or better
  2. property gasLastDate : 0
  3. global gasGC, gasDT
  4.  
  5.  
  6. on run
  7.     set thisTime to the clock in offset form
  8.     
  9.     if (gasLastDate is 0) then
  10.         set cpFold to (path to control panels folder) as string
  11.         set cdFold to ((path to system folder) as string) & "Control Panels (Disabled):"
  12.         
  13.         set gasGC to 0
  14.         set gasDT to 0
  15.         
  16.         set gcList to the entries in cpFold whose creators are in {"misc"}
  17.         set dtList to the entries in cpFold whose creators are in {"time"}
  18.         set gcLis2 to the entries in cdFold whose creators are in {"misc"}
  19.         set dtLis2 to the entries in cdFold whose creators are in {"time"}
  20.         
  21.         if (gcLis2 is not {}) then set gasGC to (cdFold & (item 1 of gcLis2)) as alias
  22.         if (dtLis2 is not {}) then set gasDT to (cdFold & (item 1 of dtLis2)) as alias
  23.         if (gcList is not {}) then set gasGC to (cpFold & (item 1 of gcList)) as alias
  24.         if (dtList is not {}) then set gasDT to (cpFold & (item 1 of dtList)) as alias
  25.         
  26.         set gasLastDate to thisTime
  27.         
  28.     else if (thisTime ≤ gasLastDate) then
  29.         
  30.         display dialog ("Du hast den PowerBook zu lange ohne Strom gelassen!" & ¬
  31.             return & return & "Prüfe bitte den Datum- und Zeiteinstellungen.") ¬
  32.             buttons {"Ja ja"} default button 1
  33.         -- Open General Controls
  34.         if gasGC is not 0 then ¬
  35.             tell application "Finder" to open gasGC
  36.         -- Open Date & Time
  37.         if gasGC is not 0 then ¬
  38.             tell application "Finder" to open gasDT
  39.         
  40.     else
  41.         CheckDayLight()
  42.         set gasLastDate to thisTime
  43.     end if
  44. end run
  45.  
  46.  
  47.  
  48.  
  49. property kdtYearLong : 1 -- 1904-2020
  50.  
  51. property kasTimeToSwitchOn : "0300" -- The time to switch on in 24 hour time
  52. property kasTimeToSwitchOff : "0200" -- The time to switch off in 24 hour time
  53.  
  54. property kasDaylightOnEur : {-1, 1, 3, 0} -- Last Sunday in March (Europe)
  55. property kasDaylightOnUSA : {1, 1, 4, 0} -- First Sunday in April (USA)
  56. property kasDaylightOff : {-1, 1, 10, 0} -- Last Sunday in October (USA, Europe?)
  57.  
  58.  
  59. on CheckDayLight()
  60.     -- Get current year
  61.     set thisYear to (the clock using format kdtYearLong) as number
  62.     
  63.     -- Set year in our nth records (are we in Europe?)
  64.     set greenwich to (time to GMT)
  65.     
  66.     -- Someone reported that this osax returned hours?!? Mine rerturns seconds
  67.     if (greenwich < -24) or (greenwich > 24) then ¬
  68.         set greenwich to greenwich / 3600 -- In hours
  69.     
  70.     -- Are we outside the USA?
  71.     if (greenwich < -10) or (greenwich > -5) then
  72.         set dstOn to kasDaylightOnEur
  73.     else
  74.         set dstOn to kasDaylighOnUSA
  75.     end if
  76.     
  77.     -- I'm not sure of Europe's off time    
  78.     set dstOff to kasDaylightOff
  79.     
  80.     -- Insert current year
  81.     set item 4 of dstOn to thisYear
  82.     set item 4 of dstOff to thisYear
  83.     
  84.     -- Get dates for this year
  85.     set thisYearOn to (the clock in sortable form using nth dstOn)
  86.     set thisYearOff to (the clock in sortable form using nth dstOff)
  87.     set thisYearNow to (the clock in extended sortable form)
  88.     
  89.     -- Add our setting hour to the On/Off dates
  90.     set thisYearOn to thisYearOn & "." & kasTimeToSwitchOn
  91.     set thisYearOff to thisYearOff & "." & kasTimeToSwitchOff
  92.     
  93.     -- Get current DST setting
  94.     set ourLoc to (adjust the clock)
  95.     set isOn to (daylight savings of ourLoc)
  96.     set shouldBeOn to (thisYearNow ≥ thisYearOn) and (thisYearNow < thisYearOff)
  97.     
  98.     -- Need to switch?
  99.     if (shouldBeOn is not isOn) then
  100.         set daylight savings of ourLoc to shouldBeOn
  101.         adjust the clock at geoposition ourLoc
  102.         display dialog ("Daylight savings time adjustment has been performed for you.") ¬
  103.             with icon note buttons {"Thankyou, Akua!"} default button 1 ¬
  104.             -- giving up after 300 -- Only MacOS 8.51 or later
  105.     end if
  106. end CheckDayLight
  107.